import {Component} from '@angular/core';
import {NgForOf} from "@angular/common";
import {ProductAlertComponent} from "../product-alert/product-alert.component";
import {Router} from "@angular/router";
import Store from "@app/shared/Store";
import {ProductRecordComponent} from "../product-record/product-record.component";
import {CheckRecordService} from "@app/shared/service/check-record.service";
import {NzButtonComponent} from "ng-zorro-antd/button";
import {HttpClient} from "@angular/common/http";

@Component({
  selector: 'app-product-list',
  standalone: true,
  imports: [
    NgForOf,
    ProductAlertComponent,
    ProductRecordComponent,
    NzButtonComponent,
  ],
  providers:[
  ],
  templateUrl: './product-list.component.html',
  styleUrl: './product-list.component.css'
})
export class ProductListComponent {
  products: Array<Product> = Store.products;
  router: Router;
  record: CheckRecordService;

  constructor(router: Router, record: CheckRecordService, private httpClient: HttpClient) {
    this.router = router;
    this.record = record;
  }

  share(name: string) {
    alert(`${name} has been shared`)
  }

  onNotify(product: Product) {
    this.record.sendCheckRecord(product);
    this.router.navigate(['/products', product.id]).then(r => {
    });
    // this.router.routerLink=['/products',product.id];
    // alert(`The product ${product.name} is on sale!`);
    // this.notify.emit(this.product);
  }

}


